package com.symbio.ishenapi.background.controller;

import com.symbio.ishenapi.background.model.TmDepartmentMembers;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Map;

/**
 * @Author: chen
 * @Description:科室成员管理层
 * @Date: Created in 11:51 2018/11/7
 * @Modified By:
 */
@RequestMapping("/TmDepartmentMembers")
public class TmDepartmentMembersController extends BaseController{

    public void save(){
        try {
            TmDepartmentMembers tmDepartmentMembers = (TmDepartmentMembers)getReqBodyObject(TmDepartmentMembers.class);
            TmDepartmentMembers.dao.saveDepartmentMembers(tmDepartmentMembers);
            renderJsonError(50001,"科室成员添加");
        }
        catch (NullPointerException e){
            renderJsonError(50002,"信息添加不完整");
        }
        catch (Exception e){
            renderJsonError(50002,"科室成员添加");
        }
    }

    /**
     * 科室列表成员查询
     * param departmentId  科室ID
     */
    public void findDepartmentList(){
        try {
            String departmentId = getPara("departmentId");
            Map map = TmDepartmentMembers.dao.findDepartmentList(getQueryModel(),departmentId);
            renderPageJsonRet(map.get("count"),map.get("data"));
        }catch (Exception e){
            renderJsonError(50001,"科室列表查询");
        }
    }

    /**
     * 科室成员启用禁用功能
     * param enabled  启用禁用参数
     *       id
     */
    public void setMembersEnabled(){
        try {
            String id = getPara("id");
            String enabled = getPara("enabled");
            TmDepartmentMembers.dao.setMembersEnabled(id,enabled);
            renderJsonError(50001,"科室成员禁用");
        }catch (Exception e){
            renderJsonError(50002,"科室成员禁用");
        }
    }
}
